<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<div class="modal-dialog x-modal-dialog" style="width: 600px;">

	<div class="modal-content">

		<div class="modal-header x-breadcrumb clearfix">

			<h2>
				<i class="glyphicon glyphicon-fire" title=""></i>&nbsp;&nbsp;<span>课程入系统</span>
			</h2>

			<button type="button" class="close" data-dismiss="modal">&times;</button>

		</div>

		<form class="form-horizontal" method="POST" action="${ctx.host}/orders-in/create-order-in" data-validate="true">

			<c:if test="${currentPrincipal.siteManager or currentPrincipal.siteServer}">
				<input type="hidden" name="siteId" value="${currentPrincipal.site.id}">
			</c:if>
			<input type="hidden" name="type" value="${type}">

			<div class="modal-body">
				<c:if test="${currentPrincipal.root or currentPrincipal.admin or currentPrincipal.areaServer or currentPrincipal.areaManager}">
					<div class="form-group x-form-group">
						<label class="col-xs-3 control-label">门店</label>
						<div class="col-xs-7" style="width: 60%;">
							<select name="siteId" class="form-control" data-validate="required">
								<c:forEach var="site" items="${persist.getSites(currentPrincipal.id)}">
									<option value="${site.id}">${site.name}</option>
								</c:forEach>
							</select>
						</div>
					</div>
				</c:if>
				<c:choose>
					<c:when test="${type eq 'individual'}">
						<input type="hidden" name="productId" value="1">
						<div class="form-group x-form-group">
							<label class="col-xs-3 control-label">产品</label>
							<div class="col-xs-7">
								<!-- <p class="form-control-static">1v1常规课</p> -->
								<select name="productType" class="form-control select2" data-validate="required">
									<option value="fast_individual">急速燃脂</option>
									<option value="shape_individual">基础塑形</option>
									<option value="young_individual">青少年专项</option>
								</select>
							</div>
						</div>
						<div class="form-group x-form-group">
							<label class="col-xs-3 control-label">课时</label>
							<div class="col-xs-7">
								<input type="text" class="form-control" name="courseHour" data-validate="required" />
							</div>
						</div>
					</c:when>
					<c:when test="${type eq 'special'}">
						<div class="form-group x-form-group">
							<label class="col-xs-3 control-label">产品</label>
							<div class="col-xs-7" style="width: 60%;">
								<select name="productType" class="form-control select2" data-validate="required">
									<option value="y_boxing_special">燃脂拳击</option>
									<option value="y_hang_training">悬挂训练</option>
									<option value="h_boxing_special">恢复再生</option>
									<option value="baby_special">孕产恢复</option>
									<!-- <option value="body_special">形体雕刻</option> -->
									<option value="vipr_special">普拉提</option>
									<option value="special_union">特色75min</option>
									<option value="special_all">全能课包</option>
									<!-- <option value="ling_hu_special">铃壶专项</option> -->
									<!-- <option value="function_special">功能训练课</option>
                  <option value="beautyback_special">专项塑性课（美人背）</option>
                  <option value="vestline_special">专项塑性课（马甲线）</option>
                  <option value="peachbutt_special">专项塑性课（蜜桃臀）</option>
                  <option value="chest_special">专项塑性课（方正胸肌）</option>
                  <option value="shoulder_special">专项塑性课（宽肩塑造）</option>
                  <option value="abdominal_special">专项塑性课（腹肌雕刻）</option> -->
								</select>·
							</div>
						</div>
						<div class="form-group x-form-group hide" id="courseAttr">
              <label class="col-xs-3 control-label">课程属性</label>
              <div class="col-xs-7">
                <select name="courseAttr" class="form-control select2" multiple="multiple">
                  <!-- <option value="normal_individual">1v1常规课</option> -->
                  <option value="fast_individual">急速燃脂</option>
                  <option value="shape_individual">基础塑形</option>
                  <option value="young_individual">青少年专项</option>
                  <option value="y_boxing_special">燃脂拳击</option>
                  <option value="y_hang_training">悬挂训练</option>
                  <option value="h_boxing_special">恢复再生</option>
                  <option value="baby_special">孕产恢复</option>
                  <option value="vipr_special">VIPR</option>
                  <option value="ling_hu_special">铃壶专项</option>
                  <option value="plt_special">普拉提</option>
                </select>
              </div>
            </div>
						<div class="form-group x-form-group">
							<label class="col-xs-3 control-label">课时</label>
							<div class="col-xs-7">
								<input type="text" class="form-control" name="courseHour" data-validate="required" />
							</div>
						</div>
					</c:when>
					<c:when test="${type eq 'posture'}">
						<input type="hidden" name="productId" value="4">
						<div class="form-group x-form-group">
							<label class="col-xs-3 control-label">产品</label>
							<div class="col-xs-7">
								<select name="productType" class="form-control select2" data-validate="required">
									<option value="posture_beauty">体态矫正美化</option>
									<option value="posture_fix">运动康复损伤疼痛处理</option>
								</select>
								<!-- <p class="form-control-static">专项体态调整课</p> -->
							</div>
						</div>
						<div class="form-group x-form-group">
							<label class="col-xs-3 control-label">课时</label>
							<div class="col-xs-7">
								<select name="courseHour" class="form-control select2" data-validate="required">
									<option value="10">10课时</option>
									<option value="20">20课时</option>
									<option value="30">30课时</option>
								</select>
							</div>
						</div>
					</c:when>
					<c:otherwise>
					</c:otherwise>
				</c:choose>


				<div class="form-group x-form-group">
					<label class="col-xs-3 control-label">用户手机</label>
					<div class="col-xs-7">
						<input type="text" class="form-control" name="mobile" data-validate="required|mobile" value="${param.mobile}" />
					</div>
				</div>
				<div class="form-group x-form-group">
					<label class="col-xs-3 control-label">验证码</label>
					<div class="col-xs-4">
						<input type="text" class="form-control" name="code" data-validate="required" /> <input type="hidden" class="form-control" name="token" />
					</div>
					<div class="col-xs-3">
						<button type="button" id="get-code" class="btn btn-primary form-control" style="height: 32px; padding: 0 .85rem;">获取验证码</button>
					</div>
				</div>
				<div class="form-group x-form-group">
					<label class="col-xs-3 control-label">姓名</label>
					<div class="col-xs-7">
						<input type="text" class="form-control" name="name" data-validate="required" value="${param.name}" />
					</div>
				</div>

				<%-- <c:if test="${currentPrincipal.root or currentPrincipal.admin}"> --%>
				<div class="form-group x-form-group">
					<label class="col-xs-3 control-label">用户渠道</label>
					<div class="pull-left col-xs-7">
						<c:set value="${persist.listUserSourceTypeParent()}" var="typeParent"></c:set>
						<c:set value="${persist.listUserSourceTypeChildren()}" var="typeChildrenMap"></c:set>
						<select name="userSourceType" class="form-control" data-validate="required">

							<c:forEach var="typeParentItem" items="${typeParent}">
								<optgroup label="${typeParentItem.name}">
									<c:choose>
										<c:when test="${not empty typeChildrenMap[typeParentItem.id.toString()]}">
											<c:forEach var="childrenTypes" items="${typeChildrenMap[typeParentItem.id.toString()]}">
												<c:if test="${currentPrincipal.siteManager or currentPrincipal.siteServer}">
													<c:choose>
														<c:when test="${not empty childrenTypes.sites}">
															<c:if test="${childrenTypes.sites.contains(currentPrincipal.site.code)}">
																<option value="${childrenTypes.id}">${typeParentItem.name}-${childrenTypes.name}</option>
															</c:if>
														</c:when>
														<c:otherwise>
															<option value="${childrenTypes.id}">${typeParentItem.name}-${childrenTypes.name}</option>
														</c:otherwise>
													</c:choose>
												</c:if>
												<c:if test="${currentPrincipal.root or currentPrincipal.admin or currentPrincipal.areaServer or currentPrincipal.areaManager}">
													<option value="${childrenTypes.id}">${typeParentItem.name}-${childrenTypes.name}</option>
												</c:if>

											</c:forEach>
										</c:when>
										<c:otherwise>
											<option value="${typeParentItem.id}">${typeParentItem.name}</option>
										</c:otherwise>
									</c:choose>
								</optgroup>
							</c:forEach>
						</select>
					</div>
				</div>
				<%-- </c:if> --%>

				<div class="form-group x-form-group">
					<label class="col-xs-3 control-label">优惠券码</label>
					<div class="col-xs-7">
						<input type="text" class="form-control" name="couponCode" />
					</div>
				</div>
			</div>

			<div class="modal-footer">
				<button type="submit" class="btn btn-success btn-shadow btn-shadow-success x-btn">确定</button>
				&nbsp;&nbsp;&nbsp;&nbsp;
				<button type="button" class="btn btn-default btn-shadow btn-shadow-default x-btn" data-dismiss="modal">取消</button>
			</div>
		</form>
	</div>
</div>

<script type="text/javascript">

  $('select[name="productType"]').select2({
    minimumResultsForSearch : -1,
    allowClear : true
  });
  
  $('select[name="productType"]').change(function(){ 
      var poroductType = $(this).children('option:selected').val();
      console.log(poroductType);
      if(poroductType == 'special_union') {
    	  $("#courseAttr").removeClass("hide")
      } else {
    	  $("#courseAttr").addClass("hide")
      }
    });
  
  $('select[name="courseAttr"]').select2({
	    minimumResultsForSearch : -1,
	    maximumSelectionLength: 2,
	    allowClear : true
	  });
  
  $('select[name="userSourceType"]').select2({
	    minimumResultsForSearch : -1,
	    allowClear : true
	  });
  
</script>
